<?php
include("../include/function.php");
dbconnect();
session_start();
?>
<script src="http://localhost/php/login/js/jquery.js">
</script>
<script>
$(document).ready(function(){

  $(".addclient").keyup(function(){
    var client = $(".addclient").val();
  
    $.ajax({url:"auto.php?value="+client,
	success:function(result){
	$(".option").show();
	$(".option").html(result);
	//alert('hi');
	$(".option").each(function()
	{
	$(".option ul li").click(function(){
	var option = $(this).html();
	$(".addclient").val(option);
	$(".option").hide();
	var optionval = $(this).attr('id');
	//alert(optionval);
    $(".clientname").val(optionval);	
	});
	}); 
	},
	
	error:function(result){
      $(".option").html(result);
    }
	});
  });
});
</script>



<?php
if($_SESSION["loggedin"]==true && $_SESSION["role"]==admin)
{
if(isset($_SESSION[msg]))
{
echo $_SESSION[msg];
unset($_SESSION[msg]);
}
?>
<?php 


?>
<form action="add.php" method="post">
<label>Project Name</label>
<input type="text" value="<?php echo $_POST['addprojectname'];?>" name="addprojectname" /><br><br>
<label>Client Name</label>

<input type="text" value="<?php echo $_POST['clientname'];?>" class="addclient" name="addclientname" /><br><br>
<input type="text" value="" style="display:none;" name="clientname" class="clientname"/>
<div class="option" style="  display:none;border: 1px solid;
    bottom: 20px;
    height: 39px;
    left: 82px;
    margin-right: 103px;
    overflow-x: auto;
    overflow-y: scroll;
    position: relative;
    width: 143px;"></div>
<label>Project Value</label>
<input type="text" value="<?php echo $_POST['addprojectvalue'];?>" name="addprojectvalue" /><br><br>
<label>Project Type</label>
<input type="radio" name="addprojecttype" value="offshore"  />offshore<br>
<input type="radio" name="addprojecttype" value="onshore" />onshore<br>

<label>Project Domain</label>
<input type="text" value="<?php echo $_POST['addprojectdomain'];?>" name="addprojectdomain" /><br><br>


<input type="submit" value="save" name="addform" />
</form>
<?php
//print_r($_POST);
if(isset($_POST['addform']))
{
$addprojectname = $_POST['addprojectname'];
$addclientname = $_POST['addclientname'];
$addprojectvalue = $_POST['addprojectvalue'];
$addprojecttype = $_POST['addprojecttype'];
$addprojectdomain = $_POST['addprojectdomain'];
$clientname = $_POST['clientname'];

$insertvalue = array();
$insertvalue[projectname] = $addprojectname;
$insertvalue[projectvalue] = $addprojectvalue;
$insertvalue[projecttype] = $addprojecttype;
$insertvalue[projectdomain] = $addprojectdomain;

insertquery("project",$insertvalue);
/* $insert = "INSERT into project(projectname,projectvalue,projecttype,projectdomain) 
values('$addprojectname','$addprojectvalue','$addprojecttype','$addprojectdomain')";
//print_r($insert);
$insertresult = mysql_query($insert); */

$insertclient ="INSERT into userclient(projectid,clientid)values(LAST_INSERT_ID(),'$clientname')";
//print_r($insertclient);
$insertval = mysql_query($insertclient);

//print_r($insertval);
header("Location: project_list.php");
}
}
else
{
header("Location: login.php");
}
?>